<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0054)http://technoplaza.suso.org/assembly/index.cgi?p=68ks2 -->
<HTML><HEAD><TITLE>The Stack, Handles, and Errors</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="Microsoft FrontPage 6.0" name=GENERATOR>
<link href="edit68k.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY bgColor=#ffffff>
<H1 class="heading">Common Mistakes<br><hr noshade>
</H1>
<P class="text">"If anything can go wrong, it will. If it can't, it will anyway."<BR>
          <BR>
  You get some strange errors messages when assembling or running your program and you don't know what's wrong? Take it easy, it is quite common :-&gt;<BR>
          <BR>
  But finding the errors in the source can be hard, VERY hard, sometimes. There are some common mistakes though if you've programmed other assembly languages before. Those include:</P>
<P class="text">* You MUST put a # before an immediate value!! There are exceptions, for example LEA 10(A7),A7, but when using MOVE, CMP and other instructions it can be a fatal error. For example, MOVE.B $10,D0 means move the byte stored at address $10 to D0! This can cause protected memory error or something like that. Always check so you've not missed any pound signs!</P>
<P class="text">* The first operand is the source, the second the destination! This is also a very common error in the beginning. We will not speak of what it could do, but instead of getting things from important places in the RAM (like, the interrupt vector), you store some trash there! Not good! Check all instructions with two operands! Most instructions have two operands.</P>
<P class="text">* Since the upper part of the register will remain there until you move another longword to the register, it may cause big problems! For example, when getting a byte from somewhere in the memory, and then you want to multiply it, you MUST be sure that the upper part of the byte is cleared out, since you don't specify any operation size (.B, .W or .L) when multiplying. To do this, use either CLR or EXT (see 2.0 Instruction summary).</P>
<P class="text">* All tables and other variables you will address with (An) must be at an even address. If you have defined it one byte before the table, it will cause the table to start at an odd address, which will probably cause in a calculator crash. To avoid this, move all such tables/arrays at the beginning of the variable section (I think, or at least it seems so, all instructions have the size 2, 4, 6...). You may also use the "even" assembly directive which aligns the table on a longword boundary.</P>
<P class="text">* Learn to use the debugging tools in the EASy68K simulator. 
Place breakpoints in your program and Trace individual instructions as you 
observe the contents of the 68000 registers. Make sure you fully understand the 
operation of each instruction and verify it's behavior as your trace through the 
code.</P>
<P class="text">Be aware that when programming an assembly language, most of the time (&gt;50%) you're sitting and correcting bugs.</P>
</BODY>
</HTML>